home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / comm.jar / content / editor / EditorPublishProgress.js < prev    next >
Encoding:
JavaScript  |  2002-04-12  |  6.2 KB  |  232 lines

  1. /* 
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *  
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *  
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  * 
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  * 
  20.  * Contributor(s): 
  21.  *   Charles Manske (cmanske@netscape.com)
  22.  */
  23.  
  24. var gInProgress = true;
  25. var gPublishData;
  26. var gPersistObj;
  27. var gTotalFileCount = 0;
  28. var gSucceededCount = 0;
  29. var gFinishedCount = 0;
  30. var gFinished = false;
  31. var gFinalMessage = GetString("PublishFailed");
  32. var gTimerID;
  33.  
  34. function Startup()
  35. {
  36.   if (!InitEditorShell())
  37.     return;
  38.  
  39.   gPublishData = window.arguments[0];
  40.   if (!gPublishData)
  41.   {
  42.     dump("No publish data!\n");
  43.     window.close();
  44.     return;
  45.   }
  46.  
  47.   gDialog.FileList          = document.getElementById("FileList");
  48.   gDialog.StatusMessage     = document.getElementById("StatusMessage");
  49.   gDialog.KeepOpen          = document.getElementById("KeepOpen");
  50.   gDialog.Close             = document.documentElement.getButton("cancel");
  51.  
  52.   SetWindowLocation();
  53.   window.title = GetString("PublishProgressCaption").replace(/%title%/, editorShell.GetDocumentTitle());
  54.  
  55.   document.getElementById("PublishToSite").value = 
  56.     GetString("PublishToSite").replace(/%title%/, TruncateStringAtWordEnd(gPublishData.siteName, 25)); 
  57.  
  58.   // Show publishing destination URL
  59.   document.getElementById("PublishUrl").value = gPublishData.publishUrl;
  60.   
  61.   // Show subdirectories only if not empty
  62.   if (gPublishData.docDir || gPublishData.otherDir)
  63.   {
  64.     if (gPublishData.docDir)
  65.       document.getElementById("docDir").value = gPublishData.docDir;
  66.     else
  67.       document.getElementById("DocSubdir").setAttribute("hidden", "true");
  68.       
  69.     if (gPublishData.publishOtherFiles && gPublishData.otherDir)
  70.       document.getElementById("otherDir").value = gPublishData.otherDir;
  71.     else
  72.       document.getElementById("OtherSubdir").setAttribute("hidden", "true");
  73.   }
  74.   else
  75.     document.getElementById("Subdirectories").setAttribute("hidden", "true");
  76.  
  77.   // Add the document to the "publish to" list as quick as possible!
  78.   SetProgressStatus(gPublishData.filename, "busy");
  79.  
  80.   if (gPublishData.publishOtherFiles)
  81.   {
  82.     // When publishing images as well, expand list to show more items
  83.     gDialog.FileList.setAttribute("rows", 5);
  84.     window.sizeToContent();
  85.   }
  86.  
  87.   // Now that dialog is initialized, we can start publishing
  88.   window.opener.StartPublishing();
  89. }
  90.  
  91. // this function is to be used when we cancel persist's saving
  92. // since not all messages will be returned to us if we cancel
  93. // this function changes status for all non-done/non-failure to failure
  94. function SetProgressStatusCancel()
  95. {
  96.   var listitems = document.getElementsByTagName("listitem");
  97.   if (!listitems)
  98.     return;
  99.  
  100.   for (var i=0; i < listitems.length; i++)
  101.   {
  102.     var attr = listitems[i].getAttribute("progress");
  103.     if (attr != "done" && attr != "failed")
  104.       listitems[i].setAttribute("progress", "failed");
  105.   }
  106. }
  107.  
  108. // Add filename to list of files to publish
  109. // or set status for file already in the list
  110. // Returns true if file was in the list
  111. function SetProgressStatus(filename, status)
  112. {
  113.   if (!filename)
  114.     return false;
  115.  
  116.   if (!status)
  117.     status = "busy";
  118.  
  119.   // Just set attribute for status icon 
  120.   // if we already have this filename 
  121.   var listitems = document.getElementsByTagName("listitem");
  122.   if (listitems)
  123.   {
  124.     for (var i=0; i < listitems.length; i++)
  125.     {
  126.       if (listitems[i].getAttribute("label") == filename)
  127.       {
  128.         listitems[i].setAttribute("progress", status);
  129.         return true;
  130.       }
  131.     }
  132.   }
  133.   // We're adding a new file item to list
  134.   gTotalFileCount++;
  135.  
  136.   var listitem = document.createElementNS(XUL_NS, "listitem");
  137.   if (listitem)
  138.   {
  139.     listitem.setAttribute("class", "listitem-iconic progressitem");
  140.     // This triggers CSS to show icon for each status state
  141.     listitem.setAttribute("progress", status);
  142.     listitem.setAttribute("label", filename);
  143.     gDialog.FileList.appendChild(listitem);
  144.   }
  145.   return false;
  146. }
  147.  
  148. function SetProgressFinished(filename, networkStatus)
  149. {
  150.   if (filename)
  151.   {
  152.     var status = networkStatus ? "failed" : "done";
  153.     if (networkStatus == 0)
  154.       gSucceededCount++;
  155.  
  156.     if (SetProgressStatus(filename, status))
  157.       gFinishedCount++;
  158.   }
  159.  
  160.   if (networkStatus != 0)
  161.   {
  162.     // XXX Interpret networkStatus and call SetStatusMessage() with 
  163.     //  appropriate error description.
  164.     if (filename == gPublishData.filename)
  165.       gFinalMessage = GetString("PublishFailed");
  166.     else
  167.       gFinalMessage = GetString("PublishSomeFileFailed");
  168.   }
  169.   else if (gFinishedCount == gTotalFileCount || !filename)
  170.   {
  171.     gFinished = true;
  172.     gDialog.Close.setAttribute("label", GetString("Close"));
  173.     gFinalMessage = GetString("PublishCompleted");
  174.   }
  175.   SetStatusMessage(gFinalMessage);
  176. }
  177.  
  178. function SetStatusMessage(message)
  179. {
  180.   gDialog.StatusMessage.value = message;
  181.   window.sizeToContent();
  182. }
  183.  
  184. function CheckKeepOpen()
  185. {
  186.   if (gTimerID)
  187.   {
  188.     clearTimeout(gTimerID);
  189.     gTimerID = null;
  190.   }
  191. }
  192.  
  193. function onClose()
  194. {
  195.   if (gTimerID)
  196.   {
  197.     clearTimeout(gTimerID);
  198.     gTimerID = null;
  199.   }
  200.  
  201.   if (!gFinished && gPersistObj)
  202.   {
  203.     try {
  204.       gPersistObj.cancelSave();
  205.     } catch (e) {}
  206.   }
  207.   SaveWindowLocation();
  208.  
  209.   // Tell caller so they can cleanup and restore editability
  210.   window.opener.FinishPublishing();
  211.   return true;
  212. }
  213.  
  214. function RequestCloseDialog()
  215. {
  216.   if (gFinished && !gDialog.KeepOpen.checked)
  217.   {
  218.     // Leave window open a minimum amount of time 
  219.     gTimerID = setTimeout("CloseDialog();", 3000);
  220.   }
  221.   // If window remains open, be sure final message is set
  222.   SetStatusMessage(gFinalMessage);
  223. }
  224.  
  225. function CloseDialog()
  226. {
  227.   SaveWindowLocation();
  228.   window.opener.FinishPublishing();
  229.   try {
  230.     window.close();
  231.   } catch (e) {}
  232. }